$(document).ready(function () {


    getOrders(0);

    $('#searchForm').submit(function() {
        getOrders(0 , $("form").serialize());
    });

    $('.showpage').on('click','a',function() {
        if($(this).attr('page').trim() == $('.current').html().trim()) {
            return false;
        }
        //console.log('form='+$("form").serialize());
        getOrders($(this).attr('page').trim() , $("form").serialize()+'&page='+$(this).attr('page').trim());

    })

    $('#reset').click(function(){
        getOrders(0);
    })

});
function getOrders(page ,datas) {

    datas = datas || '';

    $.ajax({type:'post',data:datas , url:SITE_PATH+'admin/report/orderPull',success:function(j) {
        if(!j['pieces'].length) {
            $('#listTBody').html('');
            $('.showpage').html('');
            alert('查无数据');
            return;
        }
        var listHtml = '';
        for(var k in j.pieces) {
            var piece = j.pieces[k];
            listHtml += '<tr><td class="id">'+piece.id+'&nbsp;</td><td>&nbsp;'+piece.pieceCode+'&nbsp;</td><td>&nbsp;'+piece.orderCode+'</td><td>'+piece.address_sender+'</td><td>'+piece.phone_sender+'</td><td>'+piece.name_sender+'</td><td>'+piece.address_recipient+'</td><td>'+piece.phone_recipient+'</td><td>'+piece.name_recipient+'</td><td>'+piece.time_add+'</td><td'+((j.users[piece.user_id].phone==piece.phone_sender)?'':' class="wrong"')+'>'+(j.users[piece.user_id].phone?j.users[piece.user_id].phone:'')+'</td><td>'+piece.price_goods+'<br>(需'+piece.price_pop+')</td><td>'+piece.price+'</td><td>'+piece.type_pay+'</td><td>'+piece.type_product+'</td><td>'+piece.state_pay+'</td><td class="state" dataState="'+piece.state+'|'+piece.state_in+'">'+piece.state_name+'<br>('+piece.state_in_name+')</td><td>操作</td><td>'+piece.comId+'</td><td>'+j.com[piece.comId]+'</td></tr>';
        }
        $('#listTBody').html(listHtml);
        $('.showpage').html(j['pages']);
    }});
}

